﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Domain;

namespace Northwind
{
    class Program
    {
        static void Main(string[] args)
        {
            Database.SetInitializer(new NorthwindDbInitializerStratege());
            
            //Create
            //using (var context=new NorthwindDbContext())
            //{
            //    var customer = new Customer { Name="hello"};
            //    context.Customers.Add(customer);
            //    context.SaveChanges();

            //}
            ////Update
            //using (var context = new NorthwindDbContext())
            //{
            //    var customer = context.Customers.Find(1);
            //    customer.Name = "Modified";
            //    context.SaveChanges();
            //}
            ////Remove
            //using (var context = new NorthwindDbContext())
            //{
            //    var customer = context.Customers.Find(1);
            //    if (customer!=null)
            //    {
            //        context.Customers.Remove(customer);
            //        context.SaveChanges();
            //    }
            //}
            //Query
            using (var context = new NorthwindDbContext())
            {
                foreach (var customer in context.Customers)
                {
                    Console.WriteLine($"\t{customer.Name}");
                    foreach (var purchase in customer.Purchases)
                    {
                        Console.WriteLine($"\t\t{purchase.Description},{purchase.Price},{purchase.Date}");
                        foreach (var purchaseItem in purchase.PurchaseItems)
                        {
                            Console.WriteLine($"\t\t\t{purchaseItem.Detail},{purchaseItem.Price}");
                        }
                    }

                }
            }
            Console.ReadKey();
        }
    }
}
